/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { Module, MiddlewareConsumer, RequestMethod } from '@nestjs/common';
import { HelloModule } from './modules/hello/hello.module';
import { ExceptionModule } from './modules/exception/exception.module';
import { LoggerMiddleware } from './common/middleware/logger.middleware';
@Module({
  imports: [HelloModule, ExceptionModule],
})
export class AppModule {
  /* 
      consumer:消费者，在生产消费这样的开发模式中，生产者去生产，给消费者去消费
        类型：MiddlewareConsumer
      apply：应用到  LoggerMiddleware 中间件
      exclude：{ path: 'hello', method: RequestMethod.POST } 符合这个路径和方法的不走这个中间件
      forRoutes：应用到hello对应的路径


    */
  configure(consumer: MiddlewareConsumer) {
    // 为hello 路由添加中间件
    consumer
      .apply(LoggerMiddleware)
      .exclude({ path: 'hello', method: RequestMethod.POST })
      .forRoutes('hello');
  }
}
